package com.yintao.ytframe.base.juc;

import java.util.ArrayList;
import java.util.List;

public class VolatileTest {

    volatile static int size = 0;

    public static List<Integer> myList = new ArrayList<Integer>();

    public void addMy(Integer i) {
        myList.add(i);
    }

    public Integer sizeMy() {
        return myList.size();
    }

    public static void main(String[] args) {
        VolatileTest volatileTest = new VolatileTest();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 110; i++) {
                    synchronized (this) {
                        volatileTest.addMy(i);
                        System.out.println(i);
                        size = volatileTest.sizeMy();
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    if (size == 100) {
                        break;
                    }
                }
                System.out.println("555555555555555555555555");
            }
        }).start();

    }
}
